package com.dxy.yesas2020goals.study.partone.disignpattern.singletonpattern.containersingleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author victorydeng
 * @Classname Containersingleton
 * @Description TODO
 * @Date 2020/2/28 19:40
 * @Created by victorydeng
 */
public class ContainerSingleton {

  private static ContainerSingleton CONTAINER_SINGLETON;

  private ContainerSingleton() {
  }
  private static Map<String, ContainerSingleton> ioc = new ConcurrentHashMap<String, ContainerSingleton>();

  public static ContainerSingleton getInstance() {
    synchronized (ioc) {
      if (ioc.containsKey("instance")) {
        return ioc.get("instance");
      } else {
        CONTAINER_SINGLETON = new ContainerSingleton();
        try {
          ioc.put("instance", CONTAINER_SINGLETON);
        } catch (Exception e) {
          e.printStackTrace();
        }
        return CONTAINER_SINGLETON;
      }
    }
  }
}
